package com.acwing.partition12;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/9 17:21
 */
public class AC1185单词游戏 {

    private static final int N = 30;
    private static int[] din = new int[N], dout = new int[N], parent = new int[N];
    private static boolean[] st = new boolean[N];

    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = Integer.parseInt(reader.readLine());
        while (t-- > 0) {
            n = Integer.parseInt(reader.readLine());
            for (int i = 0; i < N; i++) {
                din[i] = dout[i] = 0;
                parent[i] = i;
                st[i] = false;
            }
            for (int i = 0; i < n; i++) {
                String s = reader.readLine();
                int u = s.charAt(0) - 'a', v = s.charAt(s.length() - 1) - 'a';
                st[u] = st[v] = true;
                din[v]++;
                dout[u]++;
                parent[find(u)] = find(v);
            }
            if (resolve()) writer.write("Ordering is possible.\n");
            else writer.write("The door cannot be opened.\n");
        }
        writer.flush();
    }

    private static boolean resolve() {
        //有向图存在欧拉路径的判定
        int start = 0, end = 0;
        for (int i = 0; i < 26; i++) {
            if (din[i] != dout[i]) {
                if (din[i] == dout[i] + 1) end++;
                else if (dout[i] == din[i] + 1) start++;
                else return false;
            }
        }
        if (start > 1 || end > 1) return false;
        //连通性判断
        int t = -1;
        for (int i = 0; i < 26; i++) {
            if (st[i]) {
                if (t == -1) t = find(i);
                else if (t != find(i)) return false;
            }
        }
        return true;
    }

    private static int find(int x) {
        if (x == parent[x]) return x;
        return parent[x] = find(parent[x]);
    }
}
